import axios from 'axios'
import qs from 'qs'

let request = axios.create({
  baseURL: 'http://localhost:2345',
  timeout: 5000,

})

request.interceptors.request.use(config => {
  config.method == 'post' ? config.data = { ...qs.stringify(config.data) } : config.params = { ...config.params }
  //告诉浏览器你接受的对象的数据类型
  config.headers['Content-Type'] = 'application/X-www-form-urlencoded';
  return config
},
  error => {
    Promise.reject(error)
  })

request.interceptors.response.use(response => {
  // console.log(response)
  return response.data
},
  error => {
    return Promise.reject(error)
  }
)

export default request